package com.jinlejia.erp.ui.new_house.house;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.utils.DistanceUtil;
import com.bumptech.glide.Glide;
import com.freedom.yefeng.yfrecyclerview.FullyLinearLayoutManager;
import com.google.android.material.tabs.TabLayout;
import com.jinlejia.erp.R;
import com.jinlejia.erp.base.ApiConfig;
import com.jinlejia.erp.base.MapCallBack;
import com.jinlejia.erp.bean.SaveCookieBean;
import com.jinlejia.erp.common.WrapContentLinearLayoutManager;
import com.jinlejia.erp.databinding.ActivityDetailNewHouseBinding;
import com.jinlejia.erp.ui.common.IntentLinkedHashMapWrapper;
import com.jinlejia.erp.ui.common.ProgressDialog;
import com.jinlejia.erp.ui.common.ShareDialog;
import com.jinlejia.erp.ui.mine.process.LeftAndRightTagDecoration;
import com.jinlejia.erp.ui.new_house.adapter.HorizontalHouseTypeAdapter;
import com.jinlejia.erp.ui.new_house.adapter.ListViewDownAdapter;
import com.jinlejia.erp.ui.new_house.adapter.NewHouseAdapter;
import com.jinlejia.erp.ui.new_house.adapter.RuleListAdapter;
import com.jinlejia.erp.ui.new_house.recommend.RecommendClientsActivity;
import com.jinlejia.erp.utils.CallUtils;
import com.jinlejia.erp.utils.DataFilter;
import com.jinlejia.erp.utils.DbUtil;
import com.jinlejia.erp.utils.SerializableObject;
import com.jinlejia.erp.utils.SharePTool;
import com.jinlejia.erp.utils.StringUtil;
import com.weight.CustomToast;
import com.zhy.http.okhttp.OkHttpUtils;

import org.simple.eventbus.EventBus;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Call;

/**
 * 新房详情
 */
public class DetailNewHouseActivity extends AppCompatActivity {

    public static void start(Context context, String houseCode) {
        Intent intent = new Intent(context, DetailNewHouseActivity.class);
        intent.putExtra("houseCode", houseCode);
        context.startActivity(intent);
    }

    private ProgressDialog progressDialog;
    private int scollPosition = 0;
    private ListViewDownAdapter downAdapter;
    private RuleListAdapter ruleListAdapter;
    private NewHouseAdapter housesAdapter;
    //户型图adapet
    private HorizontalHouseTypeAdapter houseTypeAdapter;

    private String houseCode, phoneNO, sales;
    private String lat, lng, county, city, address, houseTitle;
    private List<String> imgList = new ArrayList<>();
    private ArrayList<Map<String, Object>> addtionList = new ArrayList<>();
    private boolean isRuleShow, isSellShow;
    private int recommendState;
    private ArrayList<Map<String, Object>> houseIntroduceList;//楼盘介绍
    private ArrayList<Map<String, String>> dynamictList, quartersDynamicList, nearDynamicList;//楼盘详情
    private ActivityDetailNewHouseBinding binding;
    private LinkedHashMap<String, ArrayList<Map<String, Object>>> houseTypeMap = new LinkedHashMap<>();//处理后的户型数据

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_detail_new_house);
        binding.setEvent(this);
        houseCode = getIntent().getStringExtra("houseCode");
        initView();
        getData();
    }

    private void initView() {
        progressDialog = new ProgressDialog(this, "加载中...", false);
        progressDialog.show();
        binding.actionLayout.getBackground().setAlpha(0);
        binding.scrollview.smoothScrollTo(0, 0);
        binding.actionTitle.setAlpha(0);

        //楼盘相册
        binding.houseAlbum.setPointsIsVisible(false);
        binding.houseAlbum.stopAutoPlay();

        //推荐规则
        binding.ruleListView.setLayoutManager(new FullyLinearLayoutManager(this));
        binding.ruleListView.setNestedScrollingEnabled(false);
        ruleListAdapter = new RuleListAdapter(this, new ArrayList<Map<String, Object>>());
        binding.ruleListView.setAdapter(ruleListAdapter);
        binding.ruleListView.addItemDecoration(new LeftAndRightTagDecoration(this));

        //楼盘卖点
        binding.houseSellingPoint.setHasFixedSize(true);
        binding.houseSellingPoint.setLayoutManager(new FullyLinearLayoutManager(this));
        binding.houseSellingPoint.setNestedScrollingEnabled(false);
        ArrayList<Map<String, Object>> sellList = new ArrayList<>();
        downAdapter = new ListViewDownAdapter(this, sellList);
        binding.houseSellingPoint.setAdapter(downAdapter);


        //附近楼盘
        binding.circumHouse.setHasFixedSize(true);
        binding.circumHouse.setLayoutManager(new FullyLinearLayoutManager(this));
        binding.circumHouse.setNestedScrollingEnabled(false);
        ArrayList<Map<String, Object>> arrayList = new ArrayList<>();
        housesAdapter = new NewHouseAdapter(arrayList);
        binding.circumHouse.setAdapter(housesAdapter);

        //户型图
        binding.houseTypeRecycler.setLayoutManager(new WrapContentLinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
        houseTypeAdapter = new HorizontalHouseTypeAdapter(this, new ArrayList<>());
        binding.houseTypeRecycler.setAdapter(houseTypeAdapter);
        houseTypeAdapter.OnImagesListener(position -> {
           /* Intent intent = new Intent(DetailNewHouseActivity.this, HouseTypeActivity.class);
            intent.putExtra("position", position);
            EventBus.getDefault().postSticky(housetypeList, "TAG_HOUSETYPE_TAG");
            startActivity(intent);*/
            Intent intent = new Intent(DetailNewHouseActivity.this, HouseTypeDetails.class);
            intent.putExtra("picId", position);
            intent.putExtra("map",new IntentLinkedHashMapWrapper(houseTypeMap));
            intent.putExtra("picId", position);
            startActivity(intent);
        });
        housesAdapter.setOnItemClickListener((view, o) -> {
            Map<String, Object> map = (Map<String, Object>) o;
            Intent intent = new Intent(DetailNewHouseActivity.this, DetailNewHouseActivity.class);
            intent.putExtra("houseCode", map.get("houseCode").toString());
            startActivity(intent);
        });
        binding.scrollview.setScrollViewListener((scrollView, x, y, oldx, oldy) -> {
            scollPosition = y;
            if (y <= 255) {
                binding.actionLayout.getBackground().setAlpha(y);
                if (y > 100) {
                    binding.actionTitle.setAlpha(0.5f);
                    binding.backShadow.setVisibility(View.GONE);
                    binding.shareShadow.setVisibility(View.GONE);
                } else {
                    binding.actionTitle.setAlpha(0);
                    binding.backShadow.setVisibility(View.VISIBLE);
                    binding.shareShadow.setVisibility(View.VISIBLE);
                }
            } else {
                binding.actionLayout.getBackground().setAlpha(255);
                binding.actionTitle.setAlpha(1);
                binding.backShadow.setVisibility(View.GONE);
                binding.shareShadow.setVisibility(View.GONE);
            }
        });
        binding.houseAlbum.setOnItemClickListener(position -> {
           /* Intent intent = new Intent(DetailNewHouseActivity.this, ViewPagerActivity.class);
            intent.putStringArrayListExtra("imgs", (ArrayList<String>) imgList);
            intent.putExtra("position", position);
            startActivity(intent);*/

            Intent intent = new Intent(DetailNewHouseActivity.this, HousePhotosActivity.class);
            intent.putExtra("houseCode", houseCode);
            startActivity(intent);
        });

        binding.idTableLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                String title = String.valueOf(tab.getText());
                for (Map.Entry<String, ArrayList<Map<String, Object>>> entry : houseTypeMap.entrySet()) {
                    ArrayList<Map<String, Object>> value = entry.getValue();
                    if (title.equals(entry.getKey() + "(" + value.size() + ")")) {
                        houseTypeAdapter.setData(value);
                    }
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

    }

    private void getData() {
        OkHttpUtils.get().url(ApiConfig.DETAIL_NEW_HOUSE)
                .addParams("houseCode", houseCode)
                .build()
                .execute(new MapCallBack() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        call.cancel();
                        e.printStackTrace();
                    }

                    @Override
                    public void onResponse(Map<String, Object> response, int id) {
                        if (DataFilter.filter(DetailNewHouseActivity.this, response)) {
                            JSONObject data = JSON.parseObject(response.get("data").toString());
                            setData(data);
                        }
                        if (progressDialog.isShowing())
                            progressDialog.dismiss();
                    }
                });
    }

    private void setData(JSONObject data) {
        if (data.containsKey("housesInfoShow")) {
            //楼盘信息
            JSONObject houseInfo = data.getJSONObject("housesInfoShow");
            //图片
            JSONArray houseImgs = houseInfo.getJSONArray("housesImages");
            imgList.clear();
            for (int i = 0, j = houseImgs.size(); i < j; i++) {
                imgList.add(ApiConfig.MAGEHEADER_URL().concat(houseImgs.getJSONObject(i).getString("imageUrl")));
            }
            binding.houseAlbum.setImagesUrl(imgList);
            final int imgCount = imgList.size();
            binding.imgIndex.setText(1 + "/" + imgCount);
            binding.houseAlbum.setOnPageChangeListener(position -> binding.imgIndex.setText(position + 1 + "/" + imgCount));

            houseTitle = houseInfo.getString("houseName");
            binding.houseName.setText(houseTitle);
            binding.actionTitle.setText(houseTitle);
            //单价
            if (houseInfo.getIntValue("isSale") == 0) {
                binding.idHousePrice.setText("价格待定");
                binding.tvHouseTypeState.setText("待售");
                binding.tvHouseTypeState.setBackgroundColor(Color.parseColor("#FF5500"));
            } else {
                binding.tvHouseTypeState.setText("在售");
                binding.tvHouseTypeState.setBackgroundColor(Color.parseColor("#F5BC00"));
                if (!TextUtils.isEmpty(StringUtil.valueOf(houseInfo.get("price_string")))) {
                    binding.idHousePrice.setText(StringUtil.valueOf(houseInfo.get("averagePrice_string")) + "元/" + StringUtil.valueOf(houseInfo.get("price_string")) + "万");
                } else {
                    binding.idHousePrice.setText(StringUtil.valueOf(houseInfo.get("averagePrice_string")) + "元/暂无");
                }
            }
            //面积
            if (TextUtils.isEmpty(StringUtil.valueOf(houseInfo.get("squareMin_string")))) {
                binding.idArea.setText("暂无");
            } else {
                binding.idArea.setText(StringUtil.valueOf(houseInfo.get("squareMin_string")) + "-" + StringUtil.valueOf(houseInfo.get("squareMax_string")) + "㎡");
            }
            //开盘时间
            if (houseInfo.containsKey("earliestRoomDateString")) {
                binding.tvOpenHouseDate.setText("开盘：" + StringUtil.valueOf(houseInfo.get("earliestRoomDateString")));
            }
            //物业类型
            if (TextUtils.isEmpty(StringUtil.valueOf(houseInfo.get("fangPropertyType")))) {
                binding.tvHouseType.setText("暂无");
            } else {
                binding.tvHouseType.setText("类型：" + StringUtil.valueOf(houseInfo.get("fangPropertyType")));
            }
            //户型
            if (TextUtils.isEmpty(StringUtil.valueOf(houseInfo.get("roomType")))) {
                binding.tvHouseTypeHu.setText("暂无");
            } else {
                binding.tvHouseTypeHu.setText("户型：" + StringUtil.valueOf(houseInfo.get("roomType")));
            }

            //region 楼盘介绍
            if (houseInfo.containsKey("houseIntroduceList")) {
                houseIntroduceList = (ArrayList<Map<String, Object>>) JSON.parseObject(String.valueOf(houseInfo.getJSONArray("houseIntroduceList")), new TypeReference<List<Map<String, Object>>>() {
                });
                if (houseIntroduceList != null) {
                    Map<String, Object> map = houseIntroduceList.get(0);
                    Iterator iter1 = map.entrySet().iterator();
                    String houseImge = "";
                    String houseInfoText = "";
                    while (iter1.hasNext()) {
                        Map.Entry<String, String> entry = (Map.Entry<String, String>) iter1.next();
                        houseImge = String.valueOf(entry.getKey());
                        houseInfoText = String.valueOf(entry.getValue());
                    }
                    Glide.with(DetailNewHouseActivity.this)
                            .load(ApiConfig.MAGEHEADER_URL().concat(houseImge))
                            .placeholder(R.mipmap.ic_no_img)
                            .error(R.mipmap.ic_no_img)
                            .into(binding.imgHouseInfoMessage);
                    binding.tvHouseInfoMessage.setText(houseInfoText);
                } else {
                    binding.housePanJieShaoLinearLayout.setVisibility(View.GONE);
                }
            } else {
                binding.housePanJieShaoLinearLayout.setVisibility(View.GONE);
            }//endregion

            //佣金
            if (houseInfo.containsKey("commissionType") && null != houseInfo.get("commissionType")) {
                if (houseInfo.getIntValue("commissionType") == 1) {
                    binding.commission.setText(houseInfo.get("commissionStr") + "%");
                } else if (houseInfo.getIntValue("commissionType") == 2) {
                    binding.commission.setText(houseInfo.get("commissionStr") + "元/套");
                } else if (houseInfo.getIntValue("commissionType") == 3) {
                    binding.commission.setText(houseInfo.get("commissionStr") + "元/㎡");
                }
            } else {
                binding.commission.setText(houseInfo.getString("commissionStr"));
            }
            //奖励
            binding.houseRewards.setText(houseInfo.getString("incentives").replaceAll("\r|\n", ""));
            if (TextUtils.isEmpty(houseInfo.getString("incentives").replaceAll("\r|\n", ""))) {
                binding.houseRewards.setVisibility(View.GONE);
            }
            //tag
            List<String> tagList = new ArrayList<>();
            if (houseInfo.get("houseTagList") != null) {
                tagList = (List<String>) houseInfo.get("houseTagList");
            }
            if (tagList.size() > 0) {
                binding.houseTag.setTags(tagList);
            } else {
                binding.houseTag.setVisibility(View.GONE);
            }

            //促销
            if (!TextUtils.isEmpty(houseInfo.getString("salesInfo"))) {
                binding.promotion.setText(houseInfo.getString("salesInfo"));
                sales = houseInfo.getString("salesInfo");
            } else {
                binding.promotion.setVisibility(View.GONE);
                binding.promotionRecommendLine.setVisibility(View.GONE);
            }
            //加推
            if (houseInfo.get("buildingInfoList") != null && houseInfo.getJSONArray("buildingInfoList").size() > 0) {
                binding.recommend.setText("加推楼盘");
                addtionList = JSON.parseObject(houseInfo.get("buildingInfoList").toString(), new TypeReference<ArrayList<Map<String, Object>>>() {
                });
            } else {
                binding.recommend.setVisibility(View.GONE);
                binding.promotionRecommendLine.setVisibility(View.GONE);
            }
            //楼盘位置
            if (!TextUtils.isEmpty(houseInfo.getString("houseAddress"))) {
                binding.houseLocation.setText(houseInfo.getString("houseAddress"));
                address = houseInfo.getString("houseAddress");
                lat = houseInfo.getString("latitude");
                lng = houseInfo.getString("longitude");
                county = houseInfo.getString("county");
                city = houseInfo.getString("city");
                recommendState = houseInfo.getIntValue("isRecommend");
            }
            //案场
            if (houseInfo.containsKey("caseResponsible")) {
                binding.name.setText(houseInfo.getString("caseResponsible"));
                phoneNO = houseInfo.getString("tel");
            }

            //region 解析楼盘信息
            dynamictList = JSON.parseObject(houseInfo.get("basicList").toString(), new TypeReference<ArrayList<Map<String, String>>>() {
            });
            //endregion

            //region 解析小区信息
            quartersDynamicList = JSON.parseObject(houseInfo.get("areaInformationList").toString(), new TypeReference<ArrayList<Map<String, String>>>() {
            });
            //endregion

            //region 解析周边信息
            nearDynamicList = JSON.parseObject(houseInfo.get("peripheryList").toString(), new TypeReference<ArrayList<Map<String, String>>>() {
            });
            //endregion

            //-----------------推荐规则--------------------
            final ArrayList<Map<String, Object>> recommendRuleList = JSON.parseObject(houseInfo.getJSONArray("recommendRuleList").toString(), new TypeReference<ArrayList<Map<String, Object>>>() {
            });
            if (recommendRuleList.size() > 0 && !TextUtils.isEmpty(StringUtil.valueOf(recommendRuleList.get(0).get("title")))
                    && !TextUtils.isEmpty(StringUtil.valueOf(recommendRuleList.get(0).get("remark")))) {
                final ArrayList<Map<String, Object>> suList = new ArrayList<>();
                suList.add(recommendRuleList.get(0));
                ruleListAdapter.setData(suList);
                ruleListAdapter.addFooter("查看详情");
                ruleListAdapter.setOnFooterViewClickListener((view, o) -> {
                    if (ruleListAdapter.mData.size() == 1) {
                        ruleListAdapter.setData(recommendRuleList);
                        if (ruleListAdapter.mFooters.size() > 0) {
                            ruleListAdapter.mFooters.clear();
                        }
                        for (int i = 0; i <= recommendRuleList.size(); i++) {
                            ruleListAdapter.notifyItemRangeInserted(0, i);
                        }
                        ruleListAdapter.addFooter("收起");
                        if (recommendRuleList.size() == 1) {
                            isRuleShow = !isRuleShow;
                            ruleListAdapter.mFooters.clear();
                            if (isRuleShow) {
                                ruleListAdapter.addFooter("收起");
                            } else {
                                ruleListAdapter.addFooter("查看详情");
                            }
                        }
                    } else {
                        ruleListAdapter.notifyItemRangeRemoved(0, recommendRuleList.size());
                        ruleListAdapter.setData(suList);
                        if (ruleListAdapter.mFooters.size() > 0) {
                            ruleListAdapter.mFooters.clear();
                        }
                        ruleListAdapter.notifyItemRangeInserted(0, suList.size());
                        ruleListAdapter.addFooter("查看详情");
                    }
                    binding.ruleListView.scrollToPosition(0);
                });
                binding.recommendRule.setVisibility(View.VISIBLE);
            } else {
                binding.recommendRule.setVisibility(View.GONE);
            }

            //解析卖点
            final ArrayList<Map<String, Object>> sellingPointList = JSON.parseObject(houseInfo.get("sellingPointList").toString(), new TypeReference<ArrayList<Map<String, Object>>>() {
            });
            if (sellingPointList.size() > 0 && !TextUtils.isEmpty(StringUtil.valueOf(sellingPointList.get(0).get("title")))
                    && !TextUtils.isEmpty(StringUtil.valueOf(sellingPointList.get(0).get("remark")))) {
                final ArrayList<Map<String, Object>> subList = new ArrayList<>();
                subList.add(sellingPointList.get(0));
                downAdapter.setData(subList);
                downAdapter.addFooter("查看详情");
                downAdapter.setOnFooterViewClickListener((view, o) -> {
                    if (downAdapter.mData.size() == 1) {
                        downAdapter.setData(sellingPointList);
                        if (downAdapter.mFooters.size() > 0) {
                            downAdapter.mFooters.clear();
                        }
                        for (int i = 0; i <= sellingPointList.size(); i++) {
                            downAdapter.notifyItemRangeInserted(0, i);
                        }
                        downAdapter.addFooter("收起");
                        if (sellingPointList.size() == 1) {
                            isSellShow = !isSellShow;
                            downAdapter.mFooters.clear();
                            if (isSellShow) {
                                downAdapter.addFooter("收起");
                            } else {
                                downAdapter.addFooter("查看详情");
                            }
                        }
                    } else {
                        downAdapter.notifyItemRemoved(sellingPointList.size());
                        downAdapter.setData(subList);
                        if (downAdapter.mFooters.size() > 0) {
                            downAdapter.mFooters.clear();
                        }
                        downAdapter.addFooter("查看详情");
                        downAdapter.notifyItemRangeInserted(0, subList.size());
                    }
                    binding.houseSellingPoint.scrollToPosition(0);
                });
                binding.sellLayout.setVisibility(View.VISIBLE);
            } else {
                binding.sellLayout.setVisibility(View.GONE);
            }

            //region 户型图
            if (data.containsKey("housespicList")) {
                final ArrayList<Map<String, Object>> housetypeList = JSON.parseObject(data.getJSONArray("housespicList").toJSONString(), new TypeReference<ArrayList<Map<String, Object>>>() {
                });
                houseTypeMap.clear();
                binding.idTableLayout.removeAllTabs();
                if (housetypeList.size() > 0) {
                    for (Map<String, Object> map : housetypeList) {
                        String roomType = String.valueOf(map.get("roomType"));
                        if (houseTypeMap.containsKey(roomType)) {
                            houseTypeMap.get(roomType).add(map);
                        } else {
                            ArrayList<Map<String, Object>> typeList = new ArrayList<>();
                            typeList.add(map);
                            houseTypeMap.put(roomType, typeList);
                        }
                    }

                    for (Map.Entry<String, ArrayList<Map<String, Object>>> entry : houseTypeMap.entrySet()) {
                        ArrayList<Map<String, Object>> value = entry.getValue();
                        binding.idTableLayout.addTab(binding.idTableLayout.newTab().setText(entry.getKey() + "(" + value.size() + ")"));
                    }
                } else {
                    binding.housetypeLayout.setVisibility(View.GONE);
                }
            }
            //endregion
            //周边楼盘
            if (data.containsKey("recommendProjectList")) {
                ArrayList<Map<String, Object>> housepage = JSON.parseObject(String.valueOf(data.getJSONArray("recommendProjectList")), new TypeReference<ArrayList<Map<String, Object>>>() {
                });
                housesAdapter.setData(housepage);
                if (housepage.size() == 0) {
                    binding.nearbyHouse.setVisibility(View.GONE);
                    binding.circumHouse.setVisibility(View.GONE);
                }
            } else {
                binding.nearbyHouse.setVisibility(View.GONE);
                binding.circumHouse.setVisibility(View.GONE);
            }

        }
    }

    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.share:
                // 分享
                String url_icon = ApiConfig.HEADER_URL() + "T1doxVB4CT1RXrhCrK.jpg";
                ShareDialog shareDialog = new ShareDialog(DetailNewHouseActivity.this,
                        houseTitle,
                        "均价:".concat(StringUtil.valueOf(binding.idHousePrice.getText())).concat("\n地址:").concat(StringUtil.valueOf(binding.houseLocation.getText())),
                        "均价:".concat(StringUtil.valueOf(binding.idHousePrice.getText())).concat("\n地址:").concat(StringUtil.valueOf(binding.houseLocation.getText())),
                        "",
                        imgList.isEmpty() ? "" : imgList.get(0),
                        R.drawable.ic_share_house,
                        String.format(ApiConfig.HOUSE_SHARE, houseCode, DbUtil.getDB(DetailNewHouseActivity.this).single().queryById(200, SaveCookieBean.class).getCookie()),
                        url_icon);
                shareDialog.hidenWorkWechatSms();
                shareDialog.show();
                break;
            case R.id.promotion:
                //促销
                Intent intent2 = new Intent(DetailNewHouseActivity.this, PromotionActivity.class);
                intent2.putExtra("sales", sales);
                startActivity(intent2);
                break;
            case R.id.recommend:
                Intent addInttent = new Intent(DetailNewHouseActivity.this, AddtionListActivity.class);
                SerializableObject smap = new SerializableObject();
                smap.setObject(addtionList);
                addInttent.putExtra("addtionList", smap);
                startActivity(addInttent);
                //加推
                break;
            case R.id.house_location:
                //楼盘位置
                Intent intent1 = new Intent(DetailNewHouseActivity.this, HousePoiSearchActivity.class);
                intent1.putExtra("lat", lat);
                intent1.putExtra("lng", lng);
                intent1.putExtra("city", city);
                intent1.putExtra("address", address);
                intent1.putExtra("title", houseTitle);
                startActivity(intent1);
                break;
            case R.id.name:
                //联系案场
                CallUtils.CallTel(DetailNewHouseActivity.this, phoneNO);
                break;
            case R.id.house_info_layout:
                //楼盘信息
                Intent info = new Intent(DetailNewHouseActivity.this, HouseInfoActivity.class);
                EventBus.getDefault().postSticky(dynamictList, "TAG_HOUSE_INFO");
                EventBus.getDefault().postSticky(quartersDynamicList, "TAG_QUQRTERS_INFO");
                EventBus.getDefault().postSticky(nearDynamicList, "TAG_NEAR_INFO");
                startActivity(info);
                break;
            case R.id.nearby_house:
                //周边楼盘
               /* Intent nearIntent = new Intent(DetailNewHouseActivity.this, NearbyHouseListActivity.class);
                nearIntent.putExtra("city", city);
                nearIntent.putExtra("county", county);
                startActivity(nearIntent);*/
                break;
            case R.id.tvMoreRoomType:
                //更多户型
                Intent intent4 = new Intent(DetailNewHouseActivity.this, HouseTypeListActivity.class);
                EventBus.getDefault().postSticky(houseTypeMap, "TAG_HOUSETYPEONE_LIST");
                startActivity(intent4);
                break;
            case R.id.tvCheckAllHouseInfoMessage:
                //楼盘介绍查看全文
                Intent intent3 = new Intent(DetailNewHouseActivity.this, HouseIntroduceActivity.class);
                EventBus.getDefault().postSticky(houseIntroduceList, "TAG_HOUSEINTRODUCE_LIST");
                startActivity(intent3);
                break;
            case R.id.recommend_clients:
                //推荐客户
                if (recommendState == 1) {
                    CustomToast.showToast(DetailNewHouseActivity.this, "项目未上线", 2000);
                    return;
                } else if (recommendState == 2) {
                    CustomToast.showToast(DetailNewHouseActivity.this, "您已离职", 2000);
                    return;
                } else if (recommendState == 3) {
                    CustomToast.showToast(DetailNewHouseActivity.this, "渠道可不见", 2000);
                    return;
                } else {
                    //推荐客户
                    Intent rIntent = new Intent(DetailNewHouseActivity.this, RecommendClientsActivity.class);
                    rIntent.putExtra("houseCode", houseCode);
                    rIntent.putExtra("houseName", binding.houseName.getText().toString());
                    //佣金
                    rIntent.putExtra("commission", binding.commission.getText().toString());
                    //计算距离
                    if (!TextUtils.isEmpty(lat) && !TextUtils.isEmpty(lng)) {//判断经度纬度不为空 在进行后面的操作 否则parseDouble会报Null
                        LatLng p1LL = new LatLng(Double.parseDouble(lat), Double.parseDouble(lng));
                        LatLng p2LL = new LatLng(SharePTool.getLatitude(this), SharePTool.getLongitude(this));
                        DecimalFormat df = new DecimalFormat("######0.00");
                        rIntent.putExtra("distance", df.format(DistanceUtil.getDistance(p1LL, p2LL) / 1000) + "km");
                    } else {//当经度纬度为null时 给其赋一个初始值 防止程序崩溃
                        rIntent.putExtra("distance", "0km");
                    }
                    startActivity(rIntent);
                }
                break;
            default:
                break;

        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (scollPosition <= 255) {
            binding.actionLayout.getBackground().setAlpha(scollPosition);
            if (scollPosition > 100) {
                binding.actionTitle.setAlpha(0.5f);
            } else {
                binding.actionTitle.setAlpha(0);
            }
        } else {
            binding.actionTitle.setAlpha(1);
            binding.actionLayout.getBackground().setAlpha(255);
        }
    }


    @Override
    protected void onPause() {
        binding.actionTitle.setAlpha(1);
        binding.actionLayout.getBackground().setAlpha(255);
        super.onPause();
    }
}
